#include <iostream>
#include <map>
#include <set>
using namespace std;

typedef set <int> Set;
typedef Set::iterator Sit;
typedef map <int, Set> Map;
typedef Map::iterator Mit;

template <typename E>
ostream & operator << (ostream &os, const set <E> &s)
{
	typename set <E>::const_iterator it;
	os << '{';
	if (! s.empty ())
	{
		it = s.begin ();
		os << *it;
		for (++it; it != s.end (); ++it)
			os << ", " << *it;
	}
	os << '}';
	return os;
}

template <typename A, typename B>
ostream & operator << (ostream &os, const map <A, B> &m)
{
	typename map <A, B>::const_iterator it;
	os << '[';
	for (it = m.begin (); it != m.end (); ++it)
		os << '\t' << it->first << ": " << it->second << '\n';
	os << ']';
}

/********************************************************************/


Map dpath, tree;


void dpath_dfs (int u, int v)
{
	dpath[u].insert (v);
	Set &t = tree[v];
	for (Sit it = t.begin(); it != t.end(); ++it)
		dpath_dfs (u, *it);
}

void generate_dpath ()
{
	int u;
	Set &t = tree[1];
	for (Sit it = t.begin(); it != t.end(); ++it)
	{
		u = *it;
		dpath_dfs (u, u);
	}
}


int disjoints (int cities)
{
	Mit it, kt;
	Sit jt, lt;
	Set c;
	int count = cities - 1;

	for (it = dpath.begin(); it != dpath.end(); ++it)
	{
		Set &is = it->second;
		for (jt = is.begin(); jt != is.end(); ++jt)
		{
			c.clear();
			for (kt = it, ++kt; kt != dpath.end(); ++kt)
			{
				Set &ks = kt->second;
				ks.erase (*jt);
				for (lt = ks.begin(); lt != ks.end(); ++lt)
				{
					//cerr << "\t" << *jt << "\t" << *lt << "\n";
					if (*jt != kt->first)
						c.insert (*lt);
				}
			}
			//cerr << "\t\t\t" << *jt << "\n";
			//cerr << "\t\t\t" << c << " [" << c.size() << "]\n\n";
			count += c.size();
		}
	}

	return count;
}


int main ()
{
	int c, p, u, v;

	while (cin >> c >> p, !cin.fail())
	{
		tree.clear();
		while (p--)
		{
			cin >> u >> v;
			tree[u].insert (v);
		}
		//cerr << "\n\n" << tree << "\n";
		generate_dpath ();
		//cerr << dpath << "\n\n";
		cout << disjoints (c) << endl;
	}
}